package BehaviorModel.stateModel;

/**
 * 功能描述: 抽奖活动的状态, 上下文, 记录状态, 记录前后的状态的切换
 * 2024/02/20
 * <p>
 * ZhangYi
 */
public class RaffleActivity {
    private State state; // ConcreteState 中进行状态切换
    private int count = 0; // 奖品的个数


    private State canRaffleState = new CanRaffleState(this);
    private State dispenseOutState = new DispenseOutState(this);
    private State dispenseState = new DispenseState(this);
    private State noRaffleState = new NoRaffleState(this);

    /**
     * 功能描述: 初始化奖品数量,状态设置为不可抽奖的状态
     *
     * @param count
     * @return
     */
    public RaffleActivity(int count) {
        this.count = count;
        state = noRaffleState; // 不可抽奖 ,需要扣除积分,才可抽奖
    }

    /**
     * 功能描述: 扣除积分
     */
    public void deductMoney() {
        if (this.count <0 ){
            System.out.println(String.format("奖品已经抽完,奖池中的奖品数量为 %d ,请联系管理员来补充",getCount()));
            this.setCount(0);
            return;
        }
        state.deductMoney();
    }

    /**
     * 功能描述: 抽奖
     *
     * @return boolean
     */
    public void raffle() {
        // 如果当前的状态是抽奖成功
        if (state.raffle() && count > 0){
            state.dispensePrize();
        }

    }

    public State getState() {
        return state;
    }

    public void setState(State state) {
        this.state = state;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public State getCanRaffleState() {
        return canRaffleState;
    }

    public void setCanRaffleState(State canRaffleState) {
        this.canRaffleState = canRaffleState;
    }

    public State getDispenseOutState() {
        return dispenseOutState;
    }

    public void setDispenseOutState(State dispenseOutState) {
        this.dispenseOutState = dispenseOutState;
    }

    public State getDispenseState() {
        return dispenseState;
    }

    public void setDispenseState(State dispenseState) {
        this.dispenseState = dispenseState;
    }

    public State getNoRaffleState() {
        return noRaffleState;
    }

    public void setNoTaffleState(State noRaffleState) {
        this.noRaffleState = noRaffleState;
    }
}
